<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>{$_G[title]}</title>
    <meta name="keywords" content="{$_G[keywords]}">
    <meta name="description" content="{$_G[description]}">
    <meta name="render" content="webkit">
    <meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1, maximum-scale=1">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="icon" href="/static/images/common/favicon.png">
    <link rel="stylesheet" type="text/css" href="/static/css/common.css">
    <script src="/static/js/jquery.js" type="text/javascript"></script>
    <script src="/static/js/common.js" type="text/javascript"></script>
</head>
<body>
<div style="padding-bottom: 15px; margin-bottom: 15px; border-bottom: 1px #e8e8e8 solid;">
    <div style="float: right;">
        经度:<span id="lng"></span>,
        纬度:<span id="lat"></span>
        <button class="button" id="confirmBtn" style="height: 20px; line-height: 18px; margin-left: 5px; padding: 0 10px; font-size: 11px;">确定</button>
    </div>
    <span>拖动地图中"蓝色"图标到你所在的位置</span>
</div>
<div class="map" id="map" style="height: 460px; width: 100%;"></div>
<script src="https://webapi.amap.com/maps?v=1.4.0&key={setting amap_key}&callback=initMap"></script>
<script src="/static/js/dsxmap.js" type="text/javascript"></script>
<script>
    var mapObj,marker;
    function initMap() {
        mapObj = new DSXMap('map', {zoom:13});
        marker = mapObj.createMarker({draggable:true});
        mapObj.addMarker(marker);
        AMap.event.addListener(marker,'mousemove',function (e) {
            var position = e.target.getPosition();
            setLocation(position);
        });
        AMap.event.addListener(marker,'dragend',function (e) {
            var position = e.target.getPosition();
            setLocation(position);
        });
        {if $address}
        mapObj.geocoder('{$address}', function (data) {
            mapObj.map.setCenter(data[0].location);
            setLocation(data[0].location);
        }, function (status, result) {
            //alert(JSON.stringify(result));
        });
        {else}
        mapObj.setCurrentLocation(function (data) {
            mapObj.map.setCenter(data.position);
            setLocation(data.position);
        }, function (err) {
            //alert(JSON.stringify(err));
        });
        {/if}
    }
    function setLocation(position) {
        $("#lng").text(position.getLng());
        $("#lat").text(position.getLat());
        marker.setPosition([position.getLng(), position.getLat()]);
    }
    $("#confirmBtn").on('click', function () {
        if (window.parent.setLocation){
            window.parent.setLocation({
                lng:$("#lng").text(),
                lat:$("#lat").text()
            });
        }
    });
</script>
</body>
</html>